package com.hk.demo.player.http;

import android.text.TextUtils;

/**
 * @Author: zhoug
 * @Date: 2023/1/18
 * @Description:
 */
public class MyPlayUrlUtil {
    /**
     * 视频协议
     */
    public static final int PROTOCOL_RTSP = 1;//"RTSP";
    public static final int PROTOCOL_RTMP = 2;// "RTMP";
    public static final int PROTOCOL_FLV = 3;// "FLV";
    public static final int PROTOCOL_HLS = 4;//"HLS";


    /**
     * 给定的url是摄像头id还是播放地址
     *
     * @param url
     * @return
     */
    public static boolean isPlayUrl(String url) {
        if (TextUtils.isEmpty(url)) {
            return false;
        }
        return url.startsWith("http") || getUrlType(url) != 0;
    }

    /**
     * 视频格式
     * @param playUrl
     * @return
     */
    public static int getUrlType(String playUrl) {
        if (TextUtils.isEmpty(playUrl)) {
            return 0;
        }
        playUrl = playUrl.toLowerCase();
        if (playUrl.startsWith("rtmp")) {
            return PROTOCOL_RTMP;
        } else if (playUrl.startsWith("rtsp")) {
            return PROTOCOL_RTSP;
        } else if (playUrl.contains("m3u8")) {
            return PROTOCOL_HLS;
        } else if (playUrl.contains("flv")) {
            return PROTOCOL_FLV;
        }
        return 0;
    }
}
